Conditions | 1 |
Paths | 4 |
Total Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* |
||
49 | init: function () { |
||
50 | var divHeaderRight = $('div.header-right'); |
||
51 | |||
52 | searchbox.search_div = $('<div>', {class: 'next_search_div'}); |
||
53 | divHeaderRight.prepend(searchbox.search_div); |
||
54 | |||
55 | searchbox.search_icon = $('<div>', {class: 'icon-fulltextsearch'}); |
||
56 | searchbox.search_icon.css('background-image', |
||
57 | "url('/apps/fulltextsearch/img/fulltextsearch.svg')"); |
||
58 | searchbox.search_icon.fadeTo(0, 0.7); |
||
59 | searchbox.search_div.append(searchbox.search_icon); |
||
60 | |||
61 | searchbox.search_form = $('<div>'); |
||
62 | searchbox.search_form.fadeTo(0, 0); |
||
63 | |||
64 | searchbox.search_input = $('<input>', { |
||
65 | id: 'next_search_input', |
||
66 | placeholder: 'Search' |
||
67 | }); |
||
68 | searchbox.search_form.append(searchbox.search_input); |
||
69 | |||
70 | searchbox.search_more = $('<div>', {class: 'search_more'}); |
||
71 | searchbox.search_more.fadeTo(0, 0).hide(); |
||
72 | |||
73 | searchbox.search_icon_more = $('<div>', {class: 'icon-more-white icon-more-fulltextsearch'}); |
||
74 | searchbox.search_icon_more.fadeTo(0, 0); |
||
75 | searchbox.search_icon_more.on('click', function () { |
||
76 | if (curr.moreDisplayed) { |
||
|
|||
77 | searchbox.search_more.stop().fadeTo(100, 0, function () { |
||
78 | $(this).hide(); |
||
79 | }); |
||
80 | curr.moreDisplayed = false; |
||
81 | } else { |
||
82 | searchbox.search_more.stop().show().fadeTo(100, 1); |
||
83 | curr.moreDisplayed = true; |
||
84 | } |
||
85 | }); |
||
86 | searchbox.search_form.append(searchbox.search_icon_more); |
||
87 | |||
88 | searchbox.search_icon_close = $('<div>', {class: 'icon-close-white icon-close-fulltextsearch'}); |
||
89 | searchbox.search_icon_close.fadeTo(0, 0); |
||
90 | searchbox.search_icon_close.on('click', function () { |
||
91 | settings.lockSearchbox = false; |
||
92 | searchbox.search_icon_more.stop().fadeTo(100, 0); |
||
93 | searchbox.search_icon_close.stop().fadeTo(100, 0); |
||
94 | searchbox.search_more.stop().fadeTo(100, 0, function () { |
||
95 | $(this).hide(); |
||
96 | }); |
||
97 | curr.moreDisplayed = false; |
||
98 | searchbox.search_input.val(''); |
||
99 | nav.onSearchReset(); |
||
100 | }); |
||
101 | searchbox.search_form.append(searchbox.search_icon_close); |
||
102 | |||
103 | searchbox.search_form.hover(function () { |
||
104 | searchbox.search_icon.stop().fadeTo(100, 0); |
||
105 | searchbox.search_form.stop().fadeTo(100, 0.8); |
||
106 | }, function () { |
||
107 | if (settings.lockSearchbox === true) { |
||
108 | return; |
||
109 | } |
||
110 | searchbox.search_form.stop().fadeTo(500, 0); |
||
111 | searchbox.search_icon.stop().fadeTo(800, 0.7); |
||
112 | }); |
||
113 | searchbox.search_div.append(searchbox.search_form); |
||
114 | searchbox.search_div.append(searchbox.search_more); |
||
115 | |||
116 | searchbox.search_input.on('focus', function () { |
||
117 | searchbar.searching(); |
||
118 | }); |
||
119 | |||
120 | searchbox.search_input.on('input', function () { |
||
121 | |||
122 | if ($(this).val() === '') { |
||
123 | nav.onSearchReset(); |
||
124 | } |
||
125 | |||
126 | // if (settings.parentHasMethod('onEntryGenerated')) { |
||
127 | // settings.parent.onEntryGenerated(); |
||
128 | // } |
||
129 | |||
130 | if (searchbox.searchTimeout === null && searchbar.initSearch(false)) { |
||
131 | searchbox.searchTimeout = _.delay(function () { |
||
132 | searchbar.initSearch(false); |
||
133 | searchbox.searchTimeout = null; |
||
134 | }, 2000); |
||
135 | } |
||
136 | }); |
||
137 | |||
138 | fullTextSearch.options(settings.searchProviderId); |
||
139 | |||
140 | $(window).bind('keydown', function (event) { |
||
141 | if (event.ctrlKey || event.metaKey) { |
||
142 | if (String.fromCharCode(event.which).toLowerCase() === 'f') { |
||
143 | event.preventDefault(); |
||
144 | searchbar.searching(); |
||
145 | } |
||
146 | } |
||
147 | }); |
||
148 | }, |
||
149 | |||
234 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.